<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/11/10
 * Time: 16:41
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\lib;

use app\common\lib\map\Tencent;
use app\common\lib\payment\wxPay;
use app\common\lib\printer\Yilian;
use app\common\lib\upload\Image;
use app\common\lib\upload\Pem;
use app\common\lib\upload\Txt;
use app\common\lib\upload\Video;
use think\Exception;

class ArrClass
{
    /**
     * 上传相关
     * @return string[]
     */
    public static function uploadAttr()
    {
        return [
            'pem' => Pem::class,
            'image' => Image::class,
            'video'=>Video::class,
            'txt'=>Txt::class
        ];
    }

    /**
     * 地图相关
     * @return string[]
     */
    public static function mapAttr()
    {
        return [
            'local' => Tencent::class
        ];
    }

    /**
     * 支付相关
     * @return string[]
     */
    public static function payAttr(){
        return [
            'wx'=>wxPay::class
        ];
    }
    public static function printer()
    {
        return [
            'yilian' => Yilian::class
        ];
    }

    /**
     * @param string $key
     * @param array $arr
     * @param array $param
     * @param bool $needInstance
     * @return mixed|object
     * @throws Exception
     * @throws \ReflectionException
     */
    public static function initClass(string $key = '', array $arr = [], array $param = [], bool $needInstance = false)
    {
        if (!array_key_exists($key, $arr)) {
            throw new Exception("{$key}不存在");
        }
        $className = $arr[$key];
        return $needInstance == true ? (new \ReflectionClass($className))->newInstanceArgs($param) : $className;
    }
}